package com.example.testthird;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.PagerAdapter;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;

// F: 接口实现的监听
//public class MainActivity extends AppCompatActivity implements View.OnClickListener {
public class MainActivity extends AppCompatActivity {

    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button bt1 = findViewById(R.id.bt1);
        EditText et1 = findViewById(R.id.et1);
        imageView = findViewById(R.id.iv1);
        ProgressBar progressBar = findViewById(R.id.pb1);

        // F: 接口实现的监听
        // bt1.setOnClickListener(this);

        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //弹出对话框
//               AlertDialog.Builder dialog= new AlertDialog.Builder(MainActivity.this);
//               dialog.setTitle("This is dialog");
//               dialog.setMessage("弹出图片吗？");
//               dialog.setCancelable(false);
//               dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
//                   @Override
//                   public void onClick(DialogInterface dialog, int which) {
//
//                   }
//               });
//               dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
//                   @Override
//                   public void onClick(DialogInterface dialog, int which) {
//
//                   }
//               });
//               dialog.show();


                //对话框显示进度条
                ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
                progressDialog.setTitle("This is ProgressDialog");
                progressDialog.setMessage("Loading....");
                progressDialog.setCancelable(true);   //可以通过返回键取消
                progressDialog.show();


                //获取EditText内容的值
                String inputText = et1.getText().toString();
                Toast.makeText(MainActivity.this, inputText, Toast.LENGTH_SHORT).show();
                //改变图片 F：
                imageView.setImageResource(R.drawable.ce);

                //显示进度条
                if (progressBar.getVisibility() == View.GONE) {
                    progressBar.setVisibility(View.VISIBLE);
                } else {
                    progressBar.setVisibility(View.GONE);
                }

                //动态跟进
//                int progress = progressBar.getProgress();
//                progress = progress+10;
//                progressBar.setProgress(progress);

            }
        });
    }

    //F：
//    @Override
//    public void onClick(View v) {
//        switch (v.getId()) {
//            case R.id.bt1:
//                imageView.setImageResource(R.drawable.ce);
//                break;
//            default:
//                break;
//
//        }
//    }
}